﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IWMAG.Scripting.AST.ObjectModel;
using IWMAG.Scripting.Types;
using IWMAG.Scripting.AST.TerminalExpressions;
using System.Reflection;
using IWMAG.Scripting.Helpers;
using IWMAG.Scripting.Interpreter;
using IWMAG.Scripting.Compiler.UserInfo;

namespace IWMAG.Scripting.AST.Statements {
    public class AliasStatement : CodeStatement {
        public CodeType Type;
        public CodeType Alias;

        public AliasStatement(Compiler.Lexeme l, CodeType type, CodeType alias)
            : base(l) {
            Type = type;
            Alias = alias != null ? alias : type;
        }

        public override void Verify(CompileTable sym, List<Compiler.IUserInfo> error) {
            if (!(Alias is ReferenceType)) {
                SendError(error, Rules.CannotAliasOverPrimitiveType);
            }
            sym.Aliases[(ReferenceType) Alias] = Type;
        }

        // by this point, all types should be dealiased so we don't need to do anything at runtime
        public override IEnumerable<Continuation> Execute(Interpreter.ScriptEngine engine, RuntimeTable sym) {
            yield break;
        }
    }
}
